package com.kasoft.emq.handler.processor;

import cn.hutool.json.JSONUtil;
import com.kasoft.emq.annotation.TopicMapping;
import com.kasoft.emq.domain.Device;
import com.kasoft.emq.handler.DeviceHandler;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@TopicMapping(topic = "/Device")
@Component
@Slf4j
public class DeviceProcessor extends AbstractProcessor {

	@Autowired
	private DeviceHandler deviceHandler;

	@Override
	public void run() {
		log.info(msg);
		Device device = JSONUtil.toBean(msg, Device.class);
		deviceHandler.save(device);
		System.out.println(new ObjectId(device.getId()).getTimestamp());
		ack.run();
	}
}
